package co.th.bjc.md.business.impl;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;

import co.th.bjc.md.business.CustomerBusiness;
import co.th.bjc.md.dao.CustomerDao;
import co.th.bjc.md.dao.CustomerDetailsDao;
import co.th.bjc.md.model.Brand;
import co.th.bjc.md.model.Category;
import co.th.bjc.md.model.CustomerData;
import co.th.bjc.md.model.CustomerDetails;
import co.th.bjc.md.model.Department;
import co.th.bjc.md.model.Hospital;
import co.th.bjc.md.model.Product;

public class CustomerBusinessImpl implements CustomerBusiness {
	
	private CustomerDao customerDao;
	private CustomerDetailsDao customerDetailsDao;

	public void setCustomerDao(CustomerDao customerDao) {
		this.customerDao = customerDao;		
	}

	public void setCustomerDetailsDao(CustomerDetailsDao customerDetailsDao) {
		this.customerDetailsDao = customerDetailsDao;
	}

	@Override
	public List<CustomerData> getCustomerByCriterai(String hospitalType,
			String hospitalDepartment, int bedCapacityMin, int bedCapacityMax,
			int presidentImp, int presidentRp, int directorImp, int directorRp,
			int limitFrom, int limitTo) throws Exception {
		return customerDao.getCustomerByCriteria(
				hospitalType, hospitalDepartment, 
				bedCapacityMin, bedCapacityMax, 
				presidentImp, presidentRp, 
				directorImp, directorRp, 
				limitFrom, limitTo);
	}
	
	@Override
	public List<Hospital> getHospital(BigDecimal regionID,String hospitalNameTH,String hospitalNameEN) throws Exception{
		
		return customerDao.getHospitalByCriteria(regionID,hospitalNameTH,hospitalNameEN);
	}

	@Override
	public CustomerData getCustomerByCriterai(BigInteger customer_id)throws Exception {
		return customerDao.getCustomerByCriterai(customer_id);
	}
	
	@Override
	public List<Department> getAllDepartment() throws Exception{
		return customerDao.getAllDepartment();
	}
	
	@Override
	public List<Category> getAllCategory() throws Exception{
		return customerDao.getAllCategory();
	}
	
	@Override
	public List<Brand> getAllBrand() throws Exception{
		return customerDao.getAllBrand();
	}
	
	@Override
	public List<Product> getListModel(BigDecimal categoryCode,BigDecimal brandCode ) throws Exception{
		return customerDao.getListModel(categoryCode, brandCode);
	}
	
	@Override
	public boolean insertCustormerDataDetails(CustomerDetails cus) throws Exception{
//		Double cusId = customerDetailsDao.insertCustomerDetails(cus);
//		if(cusId != null){
//			return true;
//		}
//		else{
//			return false;
//		}
		cus.setCustomerDataId(customerDetailsDao.getPK());
		customerDetailsDao.insertCustomerDetails(cus);
		return true;
	}

	@Override
	public CustomerDetails getCustomerDetailsByCriteria(BigInteger customer_id)throws Exception {
		return customerDao.getCustomerDetailsByCriteria(customer_id);
	}

	@Override
	public List<CustomerDetails> getCustomerDetailsByCriteria(
			String hispitalType, String hospitalDepartment, int bedCapacityMin,
			int bedCapacityMax, int presidentImp, int presidentRp,
			int directorImp, int directorRp, int limitFrom, int limitTo)
			throws Exception {
		return customerDao.getCustomerDetailsByCriteria(hispitalType, hospitalDepartment, bedCapacityMin, bedCapacityMax, presidentImp, presidentRp, directorImp, directorRp, limitFrom, limitTo);
	}

	@Override
	public List<CustomerDetails> getCustomerDetailsAll() throws Exception {
		return customerDao.getCustomerDetailsAll();
	}
}
